gusucode.com > 支持向量机工具箱 - LIBSVM OSU_SVM LS_SVM源码程序 > 支持向量机工具箱 - LIBSVM OSU_SVM LS_SVM\stprtool\datasets\sortxi.m
function [newX,newI]=sortxi(X,I,K) % [newX,newI]=sortxi(X,I,K) % % SORTXI sorts the matrix X according to the vector I and % renumbers class labels so that first class has label 1, % second class has label 2, ... etc. % % Input: % X [DxK] contains K vectors which are D-dimensional. % I [1xK] contains K integers, each integer corresponds to a vector. % K [1x1] contains numner of different inetegers in I. % % Output: % newX [DxK] vectors from X reordered according to newI. At first % places there are vectors which have label 1, then 2, etc. % newI [1xK] sorted vector I and mapped to ordinal numbers. % % Statistical Pattern Recognition Toolbox, Vojtech Franc, Vaclav Hlavac % (c) Czech Technical University Prague, http://cmp.felk.cvut.cz % Written Vojtech Franc (diploma thesis) 02.01.2000 % Modifications % 24. 6.00 V. Hlavac, comments polished. newX=zeros(size(X)); newI=zeros(size(I)); cnt=0; minClass=min(I); class=minClass; newLabel=1; for i=1:size(K,2), while isempty(find(I==class)), class=class+1; end fres=find(I==class); for j=1:max(size(fres)), cnt=cnt+1; newX(:,cnt)=X(:,fres(j)); newI(cnt)=newLabel; end class=class+1; newLabel=newLabel+1; end